"""
公告公示数据模型
"""
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, func
from sqlalchemy.ext.declarative import declarative_base
from app.database import Base

class Announcement(Base):
    """公告公示模型"""
    __tablename__ = "announcements"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(200), nullable=False, comment="公告标题")
    excerpt = Column(Text, nullable=True, comment="公告摘要")
    content = Column(Text, nullable=False, comment="公告内容")
    cover_image = Column(String(500), nullable=True, comment="封面图片URL")
    category = Column(String(50), nullable=False, comment="公告分类")
    author = Column(String(100), nullable=True, default="管理员", comment="发布者")
    is_published = Column(Boolean, default=False, comment="是否发布")
    view_count = Column(Integer, default=0, comment="浏览次数")
    published_at = Column(DateTime, nullable=True, comment="发布时间")
    created_at = Column(DateTime, default=func.now(), comment="创建时间")
    updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")

    def __repr__(self):
        return f"<Announcement(id={self.id}, title='{self.title}', category='{self.category}')>"
